﻿@model IEnumerable<Leo.Entities.Laboratorio>
@{
    ViewBag.Title = "Index";
    var ajaxoption = new AjaxOptions()
    {
        UpdateTargetId = "listarLaboratorios"
    };
}
@section scripts{
    <script type="text/javascript">
        function OnSuccessDetails(data) {
            $("#frmDetails").dialog(
                {
                    modal: true,
                    buttons: {
                        'Cerrar': function () {
                            $(this).dialog('close');
                        }
                    },
                    close: function ()
                    {
                        $(this).parent().remove();
                        $(this).remove();
                    }
                });
        }

        function OnSuccessAdd(data)
        {
            $("#dialogAdd").dialog({
                modal: true,
                width: 350,
                buttons: {
                    'Cerrar': function () {
                        $(this).dialog('close');
                    },
                    'Guardar': function () {
                        $.validator.unobtrusive.parse('#frmCreate');
                        $("#frmCreate").submit();
                    }
                },
                close: function () {
                    $(this).parent().remove();
                    $(this).remove();
                }
            });
        }

        function OnSuccessCreate(data)
        {
            if (data.ok=="true") {
                $("#dialogAdd").dialog('close');
            }
            else {
                alert(data.msg)
            }
        }
        //OnSuccessUpdate
        //OnSuccessEdit

        function OnSuccessEdit(data)
        {
            $("#dialogEdit").dialog({
                modal:true,
                width: 350,
                buttons: {
                    'Cerrar': function ()
                    {
                        $(this).dialog('close');
                    },
                    'Guardar': function ()
                    {
                        $.validator.unobtrusive.parse('#frmEdit');
                        $("#frmEdit").submit();
                    }
                },
                close: function ()
                {
                    $(this).parent().remove();
                    $(this).remove();
                }

            });
        }

        function OnSuccessUpdate(data)
        {
            if (data.ok == "true") {
                $("#dialogEdit").dialog('close');
            }
            else {
                alert(data.msg);
            }
        }

    </script>
}
<h2>Index</h2>
<p>
    @*@Html.ActionLink("Create New","Add")*@

    @Ajax.ActionLink("Nuevo Laboratorio", "Index", new AjaxOptions() {
        Url = Url.Action("Add"),
        UpdateTargetId = "showAdd",
        OnSuccess="OnSuccessAdd"
    })
</p>

@using (Ajax.BeginForm("Index", ajaxoption))
{ 
    <fieldset>
        <legend>Buscar Producto</legend>
        <b>Criterio:</b>
        @Html.TextBox("criterio")
        <input type="submit" name="btnBuscar" value="Buscar" />
    </fieldset>
    <div id="listarLaboratorios">
        @Html.Partial("_resultLaboratorios",Model)
    </div>
}

<div id="upDetails"></div>
<div id="showAdd"></div>
<div id="upEdit"></div>